"use strict";
// https://gitee.com/easyatgitee/common_eggjs_app/blob/master/app/controller/sign.js
const Controller = require('./base');
const crypto = require("crypto");
class CommentController extends Controller {
 
  async list() {
    let { ctx, app } = this; 
    let { page,pageSize,tid } = ctx.request.body; 
    page = page || 1; pageSize = pageSize  || 10;
    var offset = 0;
    var offset = (page - 1) * pageSize  
    
    let sql = `select * from  comment where 1 = 1   limit ${offset} , ${pageSize} ` 
    let data = await this.app.mysql.query(sql); 
    ctx.apiSuccess({ data });
  }
  
  async comment() {
    let { ctx, app } = this; 
    let {  content,uid,touid,tid,uname,toName } = ctx.request.body; 
    let res = await this.app.mysql.insert('comment',{ 
      content,uid,touid,tid,uname,toName,
      created_time:this.formatDate(Date.now(),"YYYY-MM-DD"),
    })
    ctx.apiSuccess(res);
  } 
   
}

module.exports = CommentController;
/*
CREATE TABLE `comment`  (
  `id` int(20) NOT NULL AUTO_INCREMENT,
  `tid` int(11),
  `uid` int(11),
  `touid` varchar(100),
  `uname` varchar(100),
  `toName` varchar(100),
  `content` varchar(200),   
  `created_time` datetime(0) DEFAULT NULL,  
  PRIMARY KEY (`id`) USING BTREE
); 
*/